﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class sy_Admin_Edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AdminCs.CheckLoginState();
    }
    protected void btnAdmin_Edit_Click(object sender, EventArgs e)
    {
        int AId = int.Parse(Request.QueryString["Id"].ToString());
        string strPwd1 = TextBox1.Text.ToString().Trim();
        string strPwd2 = TextBox2.Text.ToString().Trim();

        Md5Pw md5 = new Md5Pw();//MD5加密
        string Pwd1 = md5.Md5(strPwd1);
        string Pwd2 = md5.Md5(strPwd2);

        string sql = "select * from SyAdmin where Admin_Id=" + AId + "";
        SqlConnection conn = Class1.DBconnection();
        conn.Open();
        SqlDataAdapter daa = new SqlDataAdapter(sql, conn);
        DataSet ds1 = new DataSet();
        daa.Fill(ds1);
        DataTable dt = ds1.Tables[0];
        if (dt.Rows[0]["AdminPwd"].ToString().Trim() != Pwd1)
        {
            Response.Write("<script language='javascript'>alert('旧密码输入不正确。请重新输入！');</script>");
        }
        else
        {
            string sql1 = "update SyAdmin set AdminPwd='" + Pwd2 + "' where Admin_Id=" + AId + "";
            Class1.ExecSql(sql1);
            Session.Remove("Wn_Admin");
            Response.Write("<script>alert('密码修改成功!请重新登陆！');location.href('login.aspx')</script>");
        }

        daa.Dispose();
        ds1.Dispose();
        conn.Close();
        conn.Dispose();
        
    }
}
